﻿package mortal.game.view.copy.ChallengeCopy.newView
{
    import Message.DB.Tables.*;
    import __AS3__.vec.*;
    import com.gengine.global.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.component.gconst.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.copy.ChallengeCopy.data.*;
    import mortal.game.view.medal.*;

    public class ChallengeMapPart extends GSprite
    {
        private var _challengeData:ChallengeData;
        private var _rewardBox:GSprite;
        private var _medalSp:GSprite;
        private var _medalItem:BaseItem;
        private var _medalLvIcon:GImageBitmap;
        private var _medalLevel:BitmapNumberText;
        private var _renderVec:Vector.<ChallengeLevelRender>;
        private var _linevec:Vector.<ChallengeLineRender>;

        public function ChallengeMapPart()
        {
            this._renderVec = new Vector.<ChallengeLevelRender>;
            this._linevec = new Vector.<ChallengeLineRender>;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._rewardBox = UICompomentPool.getUICompoment(GSprite);
            this._medalSp = UICompomentPool.getUICompoment(GSprite);
            this._rewardBox.addChild(this._medalSp);
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.ChallengeMedalBg2, 740, -30, this._medalSp));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.ChallengeMedalBg, 755, 35 - 30, this._medalSp));
            this._medalItem = UICompomentPool.getUICompoment(BaseItem);
            this._medalItem.setSize(66, 68);
            var _loc_1:Boolean = false;
            this._medalItem.isDropAble = false;
            this._medalItem.isDragAble = _loc_1;
            this._medalItem.isShowLock = false;
            this._medalItem.x = 765;
            this._medalItem.y = 45 - 30;
            this._medalSp.addChild(this._medalItem);
            this._medalLvIcon = UIFactory.gImageBitmap(ImagesConst.challengeCopyNewTxt_11, 780, 90 - 30, this._medalSp);
            this._medalLevel = UIFactory.bitmapNumberText(807, 91 - 30, "FightInfoNum.png", 12, 15, -1, this._medalSp);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this.removeRenders();
            this.removeLines();
            this._medalSp.dispose(param1);
            this._medalSp = null;
            this._medalItem.dispose(param1);
            this._medalItem = null;
            this._medalLvIcon.dispose(param1);
            this._medalLvIcon = null;
            this._medalLevel.dispose(param1);
            this._medalLevel = null;
            this._rewardBox.dispose(param1);
            this._rewardBox = null;
            this._challengeData = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function getTowerToolTips() : String
        {
            var _loc_1:* = ChallengeCopyConfig.instance.getDataByTowerAndSectionAndDif(this._challengeData.tChallengCopy.tower, 5, 1);
            var _loc_2:String = "";
            if (_loc_1)
            {
                _loc_2 = Language.getStringByParam(35115, _loc_1.sectionName);
            }
            return _loc_2;
        }// end function

        private function openMagicTowerWin(event:MouseEvent) : void
        {
            if (ChallengeMagicTowerWin.isViewShow)
            {
                ChallengeMagicTowerWin.instance.hide();
            }
            else
            {
                if (this._challengeData.passLevel < this._challengeData.currentSectionMaxLevel)
                {
                    MsgManager.showRollTipsMsg(Language.getString(35116), MsgRollTipsType.msgRollTips3);
                }
                ChallengeMagicTowerWin.instance.show();
                ChallengeMagicTowerWin.instance.tower = this._challengeData.tChallengCopy.tower;
            }
            return;
        }// end function

        public function set data(param1:ChallengeData) : void
        {
            this._challengeData = param1;
            this.createLineList();
            this.createRenderList();
            this.addChild(this._rewardBox);
            var _loc_2:* = ChallengeCopyConfig.instance.getDataByTowerAndSectionAndDif(this._challengeData.tChallengCopy.tower, this._challengeData.tChallengCopy.section, 7);
            var _loc_3:* = MedalConfig.instance.getTmedalByCode(_loc_2.medalId);
            this._medalItem.source = MedalUtil.getMedalIconUrlByTmedal(_loc_3, 1);
            this._medalItem.toolTipData = _loc_3;
            if (_loc_3)
            {
                this._medalLevel.text = "" + _loc_3.typeLevel;
                this._medalSp.visible = true;
            }
            else
            {
                this._medalSp.visible = false;
            }
            return;
        }// end function

        private function createRenderList() : void
        {
            var _loc_2:ChallengeLevelRender = null;
            var _loc_3:TChallengeCopy = null;
            var _loc_4:Object = null;
            var _loc_5:int = 0;
            var _loc_6:Array = null;
            this.removeRenders();
            var _loc_1:* = this._challengeData.currentSectionMaxLevel;
            while (_loc_5 < _loc_1)
            {
                
                _loc_3 = ChallengeCopyConfig.instance.challengCopyDic[this._challengeData.tChallengCopy.tower][this._challengeData.tChallengCopy.section][(_loc_5 + 1)];
                _loc_2 = UICompomentPool.getUICompoment(ChallengeLevelRender);
                _loc_2.filters = [FilterConst.plotShowFilter];
                if (_loc_3.levelPos)
                {
                    _loc_6 = _loc_3.levelPos.split(",");
                    _loc_2.x = _loc_6[0];
                    _loc_2.y = _loc_6[1];
                }
                else
                {
                    _loc_2.x = _loc_5 * 130 + 150;
                }
                this.addChild(_loc_2);
                this._renderVec.push(_loc_2);
                _loc_4 = {data:this._challengeData, index:(_loc_5 + 1)};
                _loc_2.data = _loc_4;
                if (Global.isDebugModle)
                {
                    _loc_2.configEventListener(MouseEvent.MOUSE_DOWN, this.starMove);
                    _loc_2.configEventListener(MouseEvent.MOUSE_UP, this.stopMove);
                }
                _loc_5++;
            }
            return;
        }// end function

        private function createLineList() : void
        {
            var _loc_2:ChallengeLineRender = null;
            var _loc_3:Object = null;
            var _loc_4:TChallengeCopy = null;
            var _loc_5:int = 0;
            var _loc_6:Array = null;
            this.removeLines();
            var _loc_1:* = this._challengeData.currentSectionMaxLevel - 1;
            while (_loc_5 < _loc_1)
            {
                
                _loc_4 = ChallengeCopyConfig.instance.challengCopyDic[this._challengeData.tChallengCopy.tower][this._challengeData.tChallengCopy.section][(_loc_5 + 1)];
                _loc_2 = UICompomentPool.getUICompoment(ChallengeLineRender);
                if (_loc_4.levelPos)
                {
                    _loc_6 = _loc_4.levelPathPos.split(",");
                    _loc_2.x = _loc_6[0];
                    _loc_2.y = _loc_6[1];
                }
                else
                {
                    _loc_2.x = _loc_5 * 80 + 150;
                    _loc_2.y = 400;
                }
                this.addChild(_loc_2);
                this._linevec.push(_loc_2);
                _loc_3 = {data:this._challengeData, index:(_loc_5 + 1)};
                _loc_2.data = _loc_3;
                if ((_loc_5 + 1) > this._challengeData.passLevel)
                {
                    _loc_2.filters = [FilterConst.colorFilter2];
                }
                else
                {
                    _loc_2.filters = [];
                }
                if (Global.isDebugModle)
                {
                    _loc_2.configEventListener(MouseEvent.MOUSE_DOWN, this.starMoveLine);
                    _loc_2.configEventListener(MouseEvent.MOUSE_UP, this.stopMoveLine);
                }
                _loc_5++;
            }
            return;
        }// end function

        private function starMove(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget as ChallengeLevelRender;
            _loc_2.startDrag();
            return;
        }// end function

        private function stopMove(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget as ChallengeLevelRender;
            _loc_2.stopDrag();
            _loc_2.showCurrentPos();
            return;
        }// end function

        private function starMoveLine(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget as ChallengeLineRender;
            _loc_2.startDrag();
            return;
        }// end function

        private function stopMoveLine(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget as ChallengeLineRender;
            _loc_2.stopDrag();
            _loc_2.showCurrentPos();
            return;
        }// end function

        private function removeRenders() : void
        {
            var _loc_1:ChallengeLevelRender = null;
            for each (_loc_1 in this._renderVec)
            {
                
                _loc_1.dispose(true);
            }
            this._renderVec.length = 0;
            return;
        }// end function

        private function removeLines() : void
        {
            var _loc_1:ChallengeLineRender = null;
            for each (_loc_1 in this._linevec)
            {
                
                _loc_1.dispose(true);
            }
            this._linevec.length = 0;
            return;
        }// end function

        public function get mapPart() : GSprite
        {
            return this._rewardBox;
        }// end function

    }
}
